Add bounding box code.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 17 Jan 2004 17:38:48 +0000 (17:38 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 17 Jan 2004 17:38:48 +0000 (17:38 +0000)
gpsbabel/waypt.c

index 51c7f0f90aa53450c48aa081899aa3cde2540d35..a3a85db5f05d880c5ce6cb53267d031117cc7be4 100644 (file)
@@ -153,6 +153,36 @@ waypt_disp_all(waypt_cb cb)
        }
 }
 
+/*
+ *  Makes another pass over the data to compute bounding
+ *  box data and populates bounding box information.
+ */
+
+void
+waypt_compute_bounds(bounds *bounds)
+{
+       queue *elem, *tmp;
+       waypoint *waypointp;
+
+       /* Set data out of bounds so that even one waypoint will reset */
+       bounds->max_lat = -9999;
+       bounds->max_lon = -9999;
+       bounds->min_lat = 9999;
+       bounds->min_lon = 9999;
+
+       QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
+               waypointp = (waypoint *) elem;
+               if (waypointp->latitude > bounds->max_lat)
+                       bounds->max_lat = waypointp->latitude;
+               if (waypointp->longitude > bounds->max_lon)
+                       bounds->max_lon = waypointp->longitude;
+               if (waypointp->latitude < bounds->min_lat)
+                       bounds->min_lat = waypointp->latitude;
+               if (waypointp->longitude < bounds->min_lon)
+                       bounds->min_lon = waypointp->longitude;
+       }
+}
+
 waypoint *
 find_waypt_by_name(const char *name)
 {